wrk.method = "POST"
wrk.headers["X-Requested-With"] = "XMLHttpRequest"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
wrk.headers["User-Agent"] = "Dalvik/2.1.0 (Linux; U; Android 5.1.1; MX4 Pro Build/LMY48W)"

wrk.body='{"data":{"action":"getMyContentListV4"},"system":{"new_version":"3.7.4","os":"APP_ANDROID","channel":999,"lo":"113.951435","la":"22.54333","city":"深圳市","ssid":"lexin","session_id":"i5lrb0sc80jpe6ifncagkt4dn4","token_id":"lJdNVaOaAimgqhM\\/S6uow6hOPfivbi0UIf2EuCB+8TpyVtuTPva4j5ZPK\\/881IpqZs96dIuTvi79OwWsgti1pg==","uid":"3005428","controller":"other","machine_code":"b75928964b64c7e3","time_stamp":"1487146946","scale":"2","sign":"5ad0cc62731b680bb66adad337e15473"}}'


response = function(status, headers, body)  
	responses = responses + 1
	if body ~= nil and string.find(body,"{\"result\":0") == nil then
		failed = failed + 1
		print("body:"..body)
	end
end 

request = function()
	requests  = requests + 1
	return wrk.format(nil, path)
end



local threads = {}
local num = 1
function setup(thread)
   thread:set("id", num)
   thread:set("failed", failed)
   table.insert(threads, thread)
   num = num + 1
end

function init(args)
   requests  = 0
   responses = 0
   failed    = 0
   local msg = "thread %d created"
   print(msg:format(id))
end


function done(summary, latency, requests)
   for index, thread in ipairs(threads) do
      local id        = thread:get("id")
      local requests  = thread:get("requests")
      local responses = thread:get("responses")
	  local failed	  = thread:get("failed")
      local msg = "thread %d made %d requests and got %d responses, %d retcode!=0"
      print(msg:format(id, requests, responses,failed))
   end
end
